package com.ymatou.iapi.pushbind.testcase;

import com.google.gson.JsonObject;
import com.ymatou.iapi.pushbind.parameter.GetUserPushConfigInfoBean;
import com.ymatou.iapi.pushbind.parameter.SavePushConfigBean;
import com.ymatou.iapi.pushbind.service.GetUserPushConfigInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.PushCallService;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Random;

/**
*获取买家推送配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserPushConfigInfo{
	private static GetUserPushConfigInfoBean getuserpushconfiginfoBean;
	private static GetUserPushConfigInfoCall getuserpushconfiginfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家推送配置");
	}

	@Before
	public void caseUp() {
		getuserpushconfiginfoBean=new GetUserPushConfigInfoBean();
		getuserpushconfiginfoCall=new GetUserPushConfigInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserpushconfiginfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserPushConfigInfo_001() {
		Logger.start(true,"获取买家推送配置");
		try {
			int userid = new Random().nextInt(10000);
			SavePushConfigBean savePushConfigBean = PushCallService.initSavePushConfig(userid);
			PushCallService.savePushConfig(savePushConfigBean);
			getuserpushconfiginfoBean.setUserId(userid);
			getuserpushconfiginfoCall.setData(getuserpushconfiginfoBean);
			getuserpushconfiginfoCall.callService();
			Logger.verifyEquals("200",getuserpushconfiginfoCall.getString("Status"),"验证Status");
			JsonObject jet = getuserpushconfiginfoCall.getJsonObject().get("Result").getAsJsonObject().get("ConfigInfo").getAsJsonObject();
			Logger.verifyEquals(userid,jet.get("UserId").getAsInt(),"验证userId");
			Logger.verifyEquals(savePushConfigBean.getConfigInfo().getOrderAssistantSwitch(),jet.get("OrderAssistantSwitch").getAsInt(),"验证OrderAssistantSwitch");
			Logger.verifyEquals(savePushConfigBean.getConfigInfo().getInteractiveMsgSwitch(),jet.get("InteractiveMsgSwitch").getAsInt(),"验证InteractiveMsgSwitch");
			Logger.verifyEquals(savePushConfigBean.getConfigInfo().getNotificationSwitch(),jet.get("NotificationSwitch").getAsInt(),"验证NotificationSwitch");
			Logger.verifyEquals(savePushConfigBean.getConfigInfo().getPromotionsSwitch(),jet.get("PromotionsSwitch").getAsInt(),"验证PromotionsSwitch");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserPushConfigInfo_002() {
		Logger.start(true,"获取买家推送配置，userId为空");
		try {
			getuserpushconfiginfoCall.setData(getuserpushconfiginfoBean);
			getuserpushconfiginfoCall.callService();
			Logger.verifyEquals("406",getuserpushconfiginfoCall.getString("Status"),"验证Status,参数错误");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}